package com.prd.controller;

import com.prd.model.EntNotice;
import com.prd.service.EntNoticeService;
import com.prd.util.AjaxResult;
import com.prd.util.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "公告/通知")
@RestController
@RequestMapping("/api/entNotice")
public class EntNoticeController extends BaseController {

    @Autowired
    private EntNoticeService entNoticeService;

    @ApiOperation("查询列表")
    @GetMapping("list")
    public TableDataInfo list(@ApiParam("日期") String day, @ApiParam("1：公告、2：通知、3：通报、4：通告") Integer type, @ApiParam("标题") String title) {
        startPage();
        List<EntNotice> list = entNoticeService.listInfo(day, type, title);
        return getDataPage(list);
    }

    @ApiOperation("添加信息")
    @PostMapping("add")
    public AjaxResult add(@RequestBody EntNotice entNotice) {
        return toAjax(entNoticeService.insertInfo(entNotice));
    }

    @ApiOperation("修改信息")
    @PostMapping("update")
    public AjaxResult update(@RequestBody EntNotice entNotice) {
        return toAjax(entNoticeService.updateInfo(entNotice));
    }

    @ApiOperation("查询详情")
    @GetMapping("details/{id}")
    public AjaxResult details(@PathVariable("id") Long id) {
        return AjaxResult.success(entNoticeService.details(id));
    }

    @ApiOperation("增加抄送人")
    @PostMapping(value = "addMake/{id}/{makes}")
    public AjaxResult addMake(@ApiParam("公告/通知ID") @PathVariable("id") Long id, @ApiParam("抄送人（多个,分开）") @PathVariable("makes") Long[] makes) {
        return toAjax(entNoticeService.addMake(id, makes));
    }

    @ApiOperation("删除信息")
    @PostMapping("del/{id}")
    public AjaxResult del(@ApiParam("公告/通知ID") @PathVariable("id") Long id) {
        return toAjax(entNoticeService.removeById(id));
    }

    @ApiOperation("查询接收人是否已读")
    @GetMapping("recipient/{id}/{type}")
    public AjaxResult recipient(@ApiParam("公告/通知ID") @PathVariable("id") Long id, @ApiParam("0:全部、1：已读、2：未读") @PathVariable("type") Integer type) {
        return AjaxResult.success(entNoticeService.recipient(id, type));
    }
}
